package com.tanhua.admin.controller;


import com.tanhua.admin.service.AdminService;
import com.tanhua.model.dto.AdminDto;
import com.tanhua.model.vo.AdminVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;


@RestController
@RequestMapping("/system/users")
public class SystemController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private RedisTemplate redisTemplate;

    //获取验证码
    @GetMapping("/verification")
    public void sendCode(String uuid, HttpServletResponse response) throws IOException {
        //调用service生成验证码
        adminService.sendCode(uuid, response);
    }

    //登录
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody AdminDto adminDto) {

        Map resMap = adminService.login(adminDto);
        return ResponseEntity.ok(resMap);
    }

    //查询登录用户详情
    @PostMapping("/profile")
    public ResponseEntity loginUserInfo() {
        AdminVo vo = adminService.loginUserInfo();
        return ResponseEntity.ok(vo);
    }

    //退出登录
    @PostMapping("/logout")
    public ResponseEntity logOut() {
       ResponseEntity result= adminService.logOut();
        return ResponseEntity.ok(result);
    }

}
